import { ref } from 'vue'
import { getOrderWarrantyCategoryOptionList } from '@/api/order'

/**
 * 获取工单质保类别下拉选项
 */
export const useGetOrderWarrantyCategoryOptionsList = () => {
  // 获取下拉选项加载
  const getOptionListLoading = ref(false)

  // 获取下拉选项请求参数
  const getOptionListParam = ref({
    name: '',
    limit: 50,
    page: 1,
  })

  // 下拉选项列表
  const optionList = ref<Array<OrderWarrantyCategoryOption>>([])

  /**
   * 获取下拉选项列表
   */
  const getOptionList = async () => {
    getOptionListLoading.value = true
    const res = await getOrderWarrantyCategoryOptionList(getOptionListParam.value)
    getOptionListLoading.value = false
    if (res.data.code === 20000) {
      optionList.value = res.data.data.rows
      return ''
    }
    return res.data.message
  }

  return {
    optionList,
    getOptionListParam,
    getOptionListLoading,
    getOptionList,
  }
}
